<style scoped>
:deep(.font-medium) {
  font-weight: 400;
}
</style>
<script lang="ts" setup>
import { message } from "ant-design-vue";

import { computed, watch } from "vue";
import { useVbenForm } from "#/adapter/form";



const props = defineProps({
  catelist: {
    type: Array,
    default: [],
  },
});

const emits = defineEmits(['query', 'reset'])

const catelistcom = computed({
  get() {
    return props.catelist.map(item => {
      return {
        ...item,

      }
    });
  },
});

const [QueryForm, formApi] = useVbenForm({

  // 默认展开
  collapsed: false,
  // 所有表单项共用，可单独在表单内覆盖
  commonConfig: {
    // 所有表单项
    componentProps: {
      class: "w-full",
    },
  },
  // 提交函数
  handleReset: resetSubmit,
  handleSubmit: onSubmit,
  // 垂直布局，label和input在不同行，值为vertical
  // 水平布局，label和input在同一行
  layout: "horizontal",
  schema: [
    {
      // 组件需要在 #/adapter.ts内注册，并加上类型
      component: "Input",
      // 对应组件的参数
      componentProps: {
        placeholder: "请输入用户名",
      },
      // 字段名
      fieldName: "Name",
      // 界面显示的label
      label: "食物名称",
    },
    {
      component: "Select",
      componentProps: {
        allowClear: true,
        filterOption: true,
        options: catelistcom,
        placeholder: "请选择",
        showSearch: false,
      },
      fieldName: "CategoryId",
      label: "分类",
    },
  ],
  // 是否可展开
  showCollapseButton: true,
  submitButtonOptions: {
    content: "查询",
  },
  wrapperClass: "grid-cols-1 md:grid-cols-3",
});
function onSubmit(values: Record<string, any>) {
  console.log('查询', values);
  emits('query', values)
}

async function resetSubmit(values: Record<string, any>) {


  await formApi.resetForm()
  let temp = await formApi.getValues()
  console.log('重置', temp);

  emits('reset', temp)
}
</script>

<template>
  <QueryForm />
</template>
